'''
Created on 19 janv. 2012

@author: e0009298
'''

from google.appengine.ext import db

class Payee(db.Model):
    title = db.StringProperty(required=True, multiline=False)
    author = db.UserProperty()
    created_at = db.DateTimeProperty(auto_now_add=True)
    updated_at = db.DateTimeProperty(auto_now_add=True)

class Category(db.Model):
    title = db.StringProperty(required=True, multiline=False)
    parent_category = db.SelfReferenceProperty(required=False)
    author = db.UserProperty()
    created_at = db.DateTimeProperty(auto_now_add=True)

class Account(db.Model):
    title = db.StringProperty(required=True, multiline=False)
    account_type = db.StringProperty(required=True, multiline=False, choices=set(["TYPE1", "TYPE2", "TYPE3"]))
    number = db.StringProperty(required=False, multiline=False)
    bank_name = db.StringProperty(required=False, multiline=False)
    initial_amount = db.IntegerProperty(required=True)
    archived_amount = db.IntegerProperty(required=True)
    author = db.UserProperty()
    created_at = db.DateTimeProperty(auto_now_add=True)

class Operation(db.Model):
    srcAccount = db.ReferenceProperty(reference_class=Account, collection_name="operation_src_set")
    destAccount = db.ReferenceProperty(reference_class=Account, collection_name="operation_dest_set")
    paymode = db.StringProperty(required=True, multiline=False, choices=set(["CB", "CHEQUE", "TIP"]))
    paymode_note = db.StringProperty(required=False, multiline=False)
    date = db.DateProperty(required=True)
    payee = db.ReferenceProperty(Payee)
    category = db.ReferenceProperty(Category)
    expense = db.IntegerProperty(required=False)
    income = db.IntegerProperty(required=False)
    notes = db.StringProperty(required=False, multiline=True)
    status = db.StringProperty(required=True, multiline=False, choices=set(["PENDING", "VALIDATED", "ARCHIVED"]))
    author = db.UserProperty()
    created_at = db.DateTimeProperty(auto_now_add=True)
